<template>
	<view class="content">
		<view @click="checkVersion">检测更新</view>

		<upVersion :upLoadUrl="upLoadUrl" :newVision="newVision" :appStoreUrl='appStoreUrl' :show="show" :log="log"
			@close="close"></upVersion>
	</view>
</template>

<script>
	import upVersion from "@/components/as-upVersion/as-upVersion.vue"
	export default {
		components: {
			upVersion
		},
		data() {
			return {
				upLoadUrl: "", // 安卓下载链接
				newVision: "", // 最新版本号
				appStoreUrl: '', // AppStore链接,
				log: '',
				show: false
			}
		},
		onReady() {
			// this.checkVersion()
		},
		methods: {
			checkVersion() {
				var info = uni.getSystemInfoSync();
				uni.request({
					url: 'http://121.229.107.81:81/api/version/getVersion', //仅为示例，并非真实接口地址。
					data: {
						platform: plus.os.name.toLocaleLowerCase(),
						version: info.appWgtVersion
					},
					header: {
						'content-type': 'application/json'
					},
					method: 'POST',
					dataType: 'json',
					success: (res) => {
						console.info(res)
						//此处调用后端接口返回当前版本号和下载地址
						//回调赋值
						this.newVision = res.data.data.version
						this.appStoreUrl = ''
						this.upLoadUrl = res.data.data.url
						this.log = res.data.data.log
						this.show = true
					}
				});
			},
			close() {
				this.show = false;
			},
			toJSON() {
				return this;
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
</style>